<?

include_once 'lib/facebook.php';
include_once 'includes/config.php';
include_once 'includes/dbconnect.php';
include_once 'includes/function.php';

if (isset($_POST['share_msg']) && isset($_POST['uid'])) {

    $fb_uid = $_POST['uid'];
    $share_msg = $_POST['share_msg'];
    $share_type = $_POST['share_type'];

    if (!empty($_POST['share_with'])) {
        $share_with = $_POST['share_with'];
    } else {
        $share_with = "wall_share";
    }

    if (!empty($_POST['pid'])) {
        $pid = $_POST['pid'];
    } else {
        $pid = 0;
    }
    
    
    //$chk_q="adfasdfasdfasdf";
    //mysql_query("INSERT INTO tbl_share_record (fb_id,share_msg,photo_id,share_type,share_with,query_test,created_datetime) VALUES ('$fb_uid','$share_msg','$pid','$share_type','$share_with','$chk_q',now())") or die("MySQL Error: " . mysql_error());
    
    if (trim($share_with) == 'like') {
        $fb_uid = $_SESSION['fb_id'];
        
        $chk_q ="select * from tbl_share_record where photo_id='$pid' and fb_id='$fb_uid' and share_with='like'";
        
        $chk = mysql_query($chk_q)or die(mysql_error());
        
        
        if (mysql_num_rows($chk) == 0) {
            mysql_query("INSERT INTO tbl_share_record (fb_id,share_msg,photo_id,share_type,share_with,created_datetime) VALUES ('$fb_uid','$share_msg','$pid','$share_type','$share_with',now())") or die("MySQL Error: " . mysql_error());
           
        }
    } else {

        mysql_query("INSERT INTO tbl_share_record (fb_id,share_msg,record_id,share_type,share_with,created_datetime) VALUES ('$fb_uid','$share_msg','$pid','$share_type','$share_with',now())") or die("MySQL Error: " . mysql_error());
    }
}
?>
